package com.example.javamaday.leetcode;

public class LeetCodeTest0027 {

    public static void main(String[] args) {

    }

    public static int removeElement(int[] nums, int val) {
        int maxIndex = nums.length - 1;
        int index = 0;
        while (index <= maxIndex) {
            if (nums[maxIndex] == val) {
                maxIndex--;
                continue;
            }
            if (nums[index] == val) {
                int temp = nums[index];
                nums[index] = nums[maxIndex];
                nums[maxIndex] = temp;
                maxIndex--;
                index++;
            } else {
                index++;
            }
        }
        return maxIndex + 1;
    }
}
